#pragma GCC optimize(2)
#include <iostream>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <unordered_set>
#include <bitset>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int N=2e5+10;
bitset<N> dp;
int f[N];
ll a[N];
ll b[N];
int main()
{
	IOS;
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		b[i]=a[i]+b[i-1];
	}
	dp[1]=1;
	for(int i=1;i<=n;i++)
	{
		dp=(dp|dp<<a[i]);
		f[i]=dp[i];
		dp[i]=0;
	}
	for(int i=n+1;i<=2*n;i++)
	{
		b[i]=b[i-1];
		f[i]=dp[i];
	}
	ll ans=0;
	for(int i=1;i<=2*n;i++)
	{
		if(f[i])
		{
			ans=max(ans,b[i]-i+1);
		}
	}
	
	cout<<ans<<endl;

	return 0;
}

